package com.yjetms.controller;

import com.yjetms.entity.Stuffbasic;
import com.yjetms.repository.StuffRepository;
import com.yjetms.service.StuffbasicService;
import com.yjetms.service.StuffbasicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class StuffCreate {
    @Autowired
    StuffRepository stuffRepository;
    StuffbasicService stuffbasicService ;

    //添加员工档案
    @RequestMapping("/upload")
    public String StuffAdd(HttpServletRequest rqs) {

        stuffbasicService = new StuffbasicServiceImpl(this.stuffRepository);
        Stuffbasic stuffbasic = new Stuffbasic();
        String IDCard = rqs.getParameter("idcard");
        String StuffName = rqs.getParameter("name");
        //String Folk = rqs.getParameter("Folk");
        String Sex = rqs.getParameter("sex");
        String Phone = rqs.getParameter("phone");
        String Merriage = rqs.getParameter("mar");
        String WorkLength = rqs.getParameter("year");
        String Native = rqs.getParameter("home");
        //String Address = rqs.getParameter("Address");
        String EducationLevel=rqs.getParameter("edu");
        if (stuffbasicService.existStuff(IDCard)) {
            return "../static/upload";
        } else {
            stuffbasic.setIDcard(IDCard);
            stuffbasic.setStuffname(StuffName);
            //stuffbasic.setFolk(Folk);
            stuffbasic.setSex(Sex);
            stuffbasic.setPhone(Phone);
            stuffbasic.setMerriage(Merriage);
            stuffbasic.setWorklength(WorkLength);
            stuffbasic.setNative(Native);
           // stuffbasic.setAddress(Address);
            stuffbasicService.save(stuffbasic);
        }
        return "../static/table";
    }

}
